package com.baimawangzi.recovery.service.impl;

import com.baimawangzi.recovery.bean.PageBean;
import com.baimawangzi.recovery.bean.Transaction;
import com.baimawangzi.recovery.dao.TransactionDao;
import com.baimawangzi.recovery.dao.impl.TransactionDaoImpl;
import com.baimawangzi.recovery.service.TransactionService;

import java.util.List;

public class TransactionServiceImpl implements TransactionService {
    //private UserDao userDao=new UserDaoImpl();
    private TransactionDao transactionDao =new TransactionDaoImpl();
    @Override
    public List<Transaction> findByLimit(int m, int n) {
        return transactionDao.findByLimit(m,n);
    }

    @Override
    public PageBean<Transaction> getPageBean(int currentPage, int pageSize) {
        PageBean<Transaction> pageBean = new PageBean<>();
        pageBean.setCurrentPage(currentPage);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalSize(transactionDao.getCount());
        if (pageBean.getTotalSize()%pageSize==0){
            pageBean.setTotalPage(pageBean.getTotalSize()/pageSize);
        }
        else {
            pageBean.setTotalPage(pageBean.getTotalSize()/pageSize+1);
        }
        int m =(currentPage-1)*pageSize;
        pageBean.setData(transactionDao.findByLimit(m,pageSize));
        return pageBean;
    }
}
